package com.ocom.payconfig.controller;

import com.ocom.common.constant.PayConfigUrl;
import com.ocom.common.entity.card.EntityAd;
import com.ocom.common.enums.ResultEnum;
import com.ocom.common.resp.Result;
import com.ocom.common.utils.ResultUtil;
import com.ocom.payconfig.service.ADService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
public class AdController {

    @Autowired
    private ADService adService;

    //新增广告图（addAd）
    @PostMapping(PayConfigUrl.URLP_PayConfig_addAd)
    public Result addAd(@Validated @RequestBody EntityAd entityAd){
        int i=adService.add(entityAd.getComId(),entityAd);
        if (i>0){
            return ResultUtil.success();
        }else {
            return ResultUtil.error(ResultEnum.Err_3014);
        }
    }

    //删除广告图（delAd）
    @PostMapping(PayConfigUrl.URLP_PayConfig_delAd)
    public Result delAd(Long comId,Long id){
        int i=adService.delAd(comId,id);
        if (i>0){
            return ResultUtil.success();
        }else {
            return ResultUtil.error(ResultEnum.Err_3016);
        }
    }

    @PostMapping(PayConfigUrl.URLP_PayConfig_adList)
    public Result adList(Long comId,Integer deviceType,Integer type){
        List<EntityAd> list=adService.adList(comId,deviceType,type);
        return ResultUtil.success(list);
    }
}
